package com.hippo.core.controller;

import com.alibaba.fastjson.JSONObject;
import com.hippo.core.config.annotation.RequiresPermissions;
import com.hippo.core.service.DataSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: hippo
 */
@RestController
public class DataSourceController {
    @Autowired
    private DataSourceService dataSourceService;

    @RequiresPermissions("dataSource:list")
    @PostMapping("/getDataSourceList")
    public JSONObject getDataSourceList(@RequestBody JSONObject data) {
        return dataSourceService.getDataSourceList(data);
    }

    @RequiresPermissions("dataSource:add")
    @PostMapping("/addDataSource")
    public JSONObject addDataSource(@RequestBody JSONObject data) {
        return dataSourceService.addDataSource(data);
    }

    @RequiresPermissions("dataSource:delete")
    @DeleteMapping("/deleteDataSource/{id}")
    public JSONObject deleteDataSource(@PathVariable String id) {
        return dataSourceService.deleteDataSource(id);
    }

    @RequiresPermissions("dataSource:update")
    @PutMapping("updateDataSource")
    public JSONObject updateDataSource(@RequestBody JSONObject data) {
        return dataSourceService.updateDataSource(data);
    }

    @RequiresPermissions("dataSource:test")
    @PostMapping("/testConnect")
    public JSONObject testConnect(@RequestBody JSONObject data) {
        return dataSourceService.testConnect(data);
    }

    @RequiresPermissions("dataSource:connect")
    @PostMapping("/getConnect")
    public JSONObject getConnect(@RequestBody JSONObject data) {
        return dataSourceService.getConnect(data);
    }

    @PostMapping("/getFieldByTableName")
    public JSONObject getFieldByTableName(@RequestBody JSONObject data) {
        return dataSourceService.getFieldByTableName(data);
    }

    @PostMapping("/getCountByTableName")
    public JSONObject getCountByTableName(@RequestBody JSONObject data) {
        return dataSourceService.getCountByTableName(data);
    }

}
